"""
Input:
5
8
2
10
5
7
Output:
19
"""

def main():
    n = int(input())
    values = [int(input()) for _ in range(n)]
    
    dp = [[-1 for _ in range(n)] for _ in range(n)]
    
    def allocation(L, R):
        if dp[L][R] != -1:
            return dp[L][R]
        
        # 馋嘴拿
        if(values[L] > values[R]):
            L = (L + 1) % n
        else:
            R = (R - 1 + n) % n
        
        # 吃货拿
        if L == R:
            dp[L][R] = values[L]
        else:
            dp[L][R] = max(values[L] + allocation((L + 1) % n, R), values[R] + allocation(L, (R - 1 + n) % n))
        
        return dp[L][R]
    
    ans = 0
    for i in range(n):
        ans = max(ans, allocation((i + 1) % n, (i + n - 1) % n) + values[i])
        
    print(ans)

if __name__ == "__main__":
    main()